package com.catering.controller;

import com.catering.common.core.domain.R;
import com.catering.domain.Customer;
import com.catering.domain.CustomerTable;
import com.catering.mapper.CustomerTableMapper;
import com.catering.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private CustomerTableMapper customerTableMapper;

    @PostMapping("/insert")
    @PreAuthorize("@ss.hasPermi('customer')")
    public R<Integer> insertCustomerMessage(@RequestBody Customer customer){
        customer.setCreatetime(new Date());
        return R.ok(customerService.insertCustomerMessage(customer));
    }

    @PostMapping("/insertT")
    @PreAuthorize("@ss.hasPermi('customer')")
    public R<Integer> insertCustomerTableMessage(int tableId){
        CustomerTable customerTable = new CustomerTable();
        customerTable.setCustomerId(customerService.selectLastMessage().getId());
        customerTable.setTableId(tableId);
        return R.ok(customerTableMapper.insertSelective(customerTable));
    }

    @GetMapping("/getUId")
    @PreAuthorize("@ss.hasPermi('customer')")
    public R<Integer> getUId(){
        return R.ok(customerService.selectLastMessage().getId());
    }

}
